const express = require('express')
var cors = require('cors');
const bodyParse = require('body-parser')
const app = express()
const port = 3008
app.use(cors()); //跨域处理
app.use(bodyParse.urlencoded({
    extended: false // 这里是返回数据为false则是对象或者数组形式，为true则为任意数据类型
}))
app.use(bodyParse.json())
app.use(bodyParse.urlencoded({ extended: true }))
// 映入router
require('./routers/index')(app)
require('./sql/socket/index')

// 路径404
app.use((req, res, next) => {
    let err = new Error('Not Found!!!')
    err.status = 404
    next(err)
})
// 处理错误
app.use((err, req, res, next) => {
    res.status(err.status || 500)
    res.end('服务器错误', err.message)
})
app.listen(port, () => {
    console.log(`端口为 ${port}`)
})